/*
-------------------------------------------------------------------------------
This file is part of FlyingPaper.

Copyright (c) 2009-2010 Emilien Dupont
Also see acknowledgements in COPYING.txt

FlyingPaper is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

FlyingPaper is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with FlyingPaper. If not, see <http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------------
*/

/**
 * \file stateMananger.cpp
 * \brief StateManager's methods definition
 * \author Emilien Dupont
 *
 * This file contains the definition of the StateManager's methods.
 */

#include "stateManager.h"

StateManager::StateManager(Ogre::SceneManager *sceneMgr, Ogre::RenderWindow *renderWin, OIS::Keyboard *keyboard, OIS::Mouse *mouse)
{
    _SceneManager = sceneMgr;
    _RenderWindow = renderWin;

    _Keyboard = keyboard;
    _Mouse = mouse;

    _Keyboard->setEventCallback(this);
    _Mouse->setEventCallback(this);

    _ActiveState = 0;
}

StateManager::~StateManager()
{

}

void StateManager::addState(State *state)
{
    state->init();
    _StateList.push_back(state);
}

void StateManager::changeActiveState(Ogre::String name)
{
    for(unsigned int i = 0; i < _StateList.size(); ++i)
    {
        if(_StateList[i]->getName() == name)
        {
            _ActiveState = _StateList[i];
            _ActiveState->enter();
            return;
        }
    }
}

bool StateManager::frameStarted(const Ogre::FrameEvent &evt)
{
    _ActiveState->frameStarted(evt);
    return true;
}

bool StateManager::keyPressed(const OIS::KeyEvent &e)
{
    _ActiveState->keyPressed(e);
    return true;
}

bool StateManager::keyReleased(const OIS::KeyEvent &e)
{
    _ActiveState->keyReleased(e);
    return true;
}

bool StateManager::mouseMoved(const OIS::MouseEvent &e)
{
    _ActiveState->mouseMoved(e);
    return true;
}

bool StateManager::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
    _ActiveState->mousePressed(e, id);
    return true;
}

bool StateManager::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
{
    _ActiveState->mouseReleased(e, id);
    return true;
}
